package net.zwj.test.concurrent;

import java.util.concurrent.ThreadFactory;

public class MyThreadFactory implements ThreadFactory {

	private int counter;
	private String prefix;

	public MyThreadFactory(String prefix) {
		this.prefix = prefix;
		this.counter = 1;
	}

	@Override
	public Thread newThread(Runnable r) {
		MyThread myThread = new MyThread(r, prefix + "-" + counter);
		counter++;
		return myThread;
	}

	public static void main(String[] args) throws InterruptedException {
		MyThreadFactory myFactory = new MyThreadFactory("MyThreadFactory");
		Thread thread = myFactory.newThread(new MyTask());
		thread.start();
		thread.join();
		System.out.printf("Main: Thread information.\n");
		System.out.printf("%s\n", thread);
		System.out.printf("Main: End of the example.\n");

	}
}
